package com.cn.xiaonuo.common.utils.payutils;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.security.SecureRandom;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author luyangyang
 * @data 2022.11.01 15:01
 */
@Component
public class LakalaPayUtil {

    public static String assemblyOrderNo(String merchantNo) {
        return merchantNo + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + "002";
    }

    public static Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create();

    /**
     * 字符集固定 utf-8
     */
    public static final String ENCODING = "utf-8";
    /**
     * API schema ,固定 LKLAPI-SHA256withRSA
     */
    public final static String SCHEMA = "LKLAPI-SHA256withRSA";

    public static final String SYMBOLS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

    public static final SecureRandom RANDOM = new SecureRandom();

    public static LakalaPayUtil lakalaPayUtilNew;

    //网关
//    public static final String LAKALA_URL = "https://test.wsmsd.cn/sit";

    //商户订单退款交易
    public static final String IDMRE_FUND="/api/v3/labs/relation/idmrefund";

    public static final String IDM_REFUND_QUERY= "/api/v3/labs/query/idmrefundquery";
    //寄售
    public static String APP_ID;
    public static String MCH_ID;
    public static String SERIAL_NO;
    public static String PRIVATE_KEY;
    public static String PUBULIC_KEY;
    public static String TERM_NO;
    public static String LAKALA_URL;



    @Value("${lakalaPay.APP_ID}")
    private String app_id;

    @Value("${lakalaPay.MCH_ID}")
    private String mch_id;

    @Value("${lakalaPay.privateKey}")
    private String privateKey;

    @Value("${lakalaPay.publicKey}")
    private String publicKey;

    @Value("${lakalaPay.serialNo}")
    private String serialNo;
    @Value("${lakalaPay.termNo}")
    private String termNo;

    @Value("${lakalaPay.lakalaUrl}")
    private String lakalaUrl;


    @PostConstruct
    public void initValue() throws Exception {
        lakalaPayUtilNew=this;
        APP_ID=app_id;
        MCH_ID=mch_id;
        SERIAL_NO=serialNo;
        TERM_NO=termNo;
        LAKALA_URL=lakalaUrl;

        PRIVATE_KEY=privateKey;
        PUBULIC_KEY=publicKey;

    }


}
